#include "overlay.h"

Overlay::Overlay()
{
	m_OverlayManager = Ogre::OverlayManager::getSingletonPtr();
	m_Overlay = m_OverlayManager->create("overlay1");

	DisplayPlayername();
	DisplayScore();
	DisplayPause();

	m_Overlay->show();
}


void Overlay::DisplayPlayername()
{
	m_PlayernameContainer = static_cast<Ogre::OverlayContainer*>(m_OverlayManager->createOverlayElement("Panel", "PlayernameContainer"));
	m_PlayernameContainer->setPosition(m_PaddingLeft, m_PaddingTop);


	m_PlayernameTextArea = m_OverlayManager->createOverlayElement("TextArea", "PlayerTextArea");
	m_PlayernameTextArea->setMetricsMode(Ogre::GMM_PIXELS);
    m_PlayernameTextArea->setParameter("font_name", "font");
	m_PlayernameTextArea->setParameter("alignment", "left");
	m_PlayernameTextArea->setParameter("char_height", "72");
	m_PlayernameTextArea->setColour(Ogre::ColourValue::Red);


	m_PlayernameTextArea->setCaption("Player 1");

	m_PlayernameContainer->addChild(m_PlayernameTextArea);

	m_Overlay->add2D(m_PlayernameContainer);

}



void Overlay::DisplayScore()
{
	m_ScoreContainer = static_cast<Ogre::OverlayContainer*>(m_OverlayManager->createOverlayElement("Panel", "ScoreContainer"));
	m_ScoreContainer->setPosition(1-m_PaddingLeft, m_PaddingTop);


	m_ScoreTextArea = m_OverlayManager->createOverlayElement("TextArea", "ScoreTextArea");
	m_ScoreTextArea->setMetricsMode(Ogre::GMM_PIXELS);
    m_ScoreTextArea->setParameter("font_name", "font");
	m_ScoreTextArea->setParameter("alignment", "right");
	m_ScoreTextArea->setParameter("char_height", "72");
	m_ScoreTextArea->setColour(Ogre::ColourValue::Red);


	m_ScoreTextArea->setCaption("0");

	m_ScoreContainer->addChild(m_ScoreTextArea);

	m_Overlay->add2D(m_ScoreContainer);

}

void Overlay::SetScore(const unsigned long& p_Score)
{
	m_ScoreTextArea->setCaption(std::to_string(p_Score));
}


void Overlay::DisplayPause()
{
	m_PauseContainer = static_cast<Ogre::OverlayContainer*>(m_OverlayManager->createOverlayElement("Panel", "PauseContainer"));
	m_PauseContainer->setPosition(0.5, 0.5);


	m_PauseTextArea = m_OverlayManager->createOverlayElement("TextArea", "PauseTextArea");
	m_PauseTextArea->setMetricsMode(Ogre::GMM_PIXELS);
    m_PauseTextArea->setParameter("font_name", "font");
	m_PauseTextArea->setParameter("alignment", "center");
	m_PauseTextArea->setParameter("char_height", "96");
	m_PauseTextArea->setColour(Ogre::ColourValue::Red);


	m_PauseTextArea->setCaption("PAUSED");

	m_PauseContainer->addChild(m_PauseTextArea);

	m_Overlay->add2D(m_PauseContainer);

	m_PauseContainer->hide();
}

void Overlay::ShowPause(bool p_Pause)
{
	if (p_Pause)
	{
		m_PauseContainer->show();
	}
	else
	{
		m_PauseContainer->hide();
	}
}


void Overlay::SetDebug(Ogre::String debug)
{
	m_PlayernameTextArea->setCaption(debug);
}


Overlay::~Overlay()
{
    m_OverlayManager->destroyAllOverlayElements();
    m_OverlayManager->destroyAll();
}
